//
//  QingJia.m
//  ChatDemo-UI2.0
//
//  Created by syun on 16/3/22.
//  Copyright © 2016年 syun. All rights reserved.
//

#import "QingJia.h"
#import "QingJiaTableViewCell.h"
@implementation QingJia
NSArray *studentArr3;
NSMutableArray*mustudentArr3;
UIImageView *nodataImage;
-(id)initWithFrame:(CGRect)frame classId:(NSString *)classId timedata:(NSString *)data
{
    self=[super initWithFrame:frame];
    if (self) {
        [self loadTableView:classId timedata:data];
    }
    return self;
}
-(void)loadTableView:(NSString *)class_id timedata:(NSString *)time
{
    
    
    UILabel *label01=[[UILabel alloc]initWithFrame:CGRectMake(10,0,(self.frame.size.width-20)*0.4, 30)];
    label01.text=@"姓名";
    label01.textAlignment=NSTextAlignmentCenter;
    label01.backgroundColor=[UIColor whiteColor];
    [self addSubview:label01];
    UILabel *label02=[[UILabel alloc]initWithFrame:CGRectMake(label01.frame.origin.x+label01.frame.size.width, label01.frame.origin.y,(self.frame.size.width-20)*0.3, 30)];
    label02.text=@"班级";
    label02.textAlignment=NSTextAlignmentCenter;
    label02.backgroundColor=[UIColor whiteColor];
    [self addSubview:label02];
    
    UILabel *label03=[[UILabel alloc]initWithFrame:CGRectMake(label02.frame.origin.x+label02.frame.size.width, label01.frame.origin.y,(self.frame.size.width-20)*0.3, 30)];
    label03.text=@"请假类型";
    label03.textAlignment=NSTextAlignmentCenter;
    label03.backgroundColor=[UIColor whiteColor];
    [self addSubview:label03];
    
    _myTableView=[[UITableView alloc]initWithFrame:CGRectMake(10, label01.frame.origin.y+label01.frame.size.height+1, self.frame.size.width-20, self.frame.size.height-label01.frame.size.height-30) style:UITableViewStylePlain];
    _myTableView.tableFooterView=[[UIView alloc]init];
    _myTableView.dataSource=self;
    _myTableView.delegate=self;
    [self addSubview:_myTableView];
    
    [self studentList3:class_id timeData:time];

}
-(void)studentList3:(NSString *)cId timeData:(NSString *)timedata
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_leave_byclass" forKey:@"method"];
    [dict setObject:cId forKey:@"classid"];
    [dict setObject:timedata forKey:@"day"];
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        studentArr3=[NSArray array];
        [mustudentArr3 removeAllObjects];
        NSDictionary *dict = (NSDictionary *)resposeJson;
        
        NSDictionary *redataDic = nil;
        if ([[dict objectForKey:@"re_data"] count] > 0) {
            redataDic=[[NSDictionary alloc]initWithDictionary:[dict objectForKey:@"re_data"]];
        }else {
            return;
        }
        
        studentArr3=[redataDic objectForKeySafely:@"re_leavelist"];
        
        if (studentArr3.count>0) {
           
            studentArr3=[ConfirmationNsnull nullArr:studentArr3];
        }
        mustudentArr3=[NSMutableArray arrayWithArray:studentArr3];
        if (mustudentArr3.count>0) {
             [nodataImage removeFromSuperview];
        }else
        {
            if(!nodataImage)
            {
            nodataImage=[[UIImageView alloc]initWithFrame:CGRectMake((self->_myTableView.frame.size.width-95)/2, (self->_myTableView.frame.size.height-95)/2, 95, 95)];
            }
            nodataImage.image=[UIImage imageNamed:@"nodata"];
            [self->_myTableView addSubview:nodataImage];
            

        }
         [self->_myTableView reloadData];
        
        NSLog(@"qingjia=%@",mustudentArr3);
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}
-(void)chooseClassTouchAction:(UIButton *)sender
{
    
}
-(void)chooseTimeTouchAction:(UIButton *)sender
{

}

#pragma mark - UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [mustudentArr3 count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifier = @"cell";
    QingJiaTableViewCell *cell =(QingJiaTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell==nil) {
        cell =[[[NSBundle mainBundle]loadNibNamed:@"QingJiaTableViewCell" owner:nil options:nil] objectAtIndex:0];
    }
      cell.nameLabel.text=[[mustudentArr3 objectAtIndex:indexPath.row]objectForKey:@"studentname"];
      cell.classLabel.text=[[mustudentArr3 objectAtIndex:indexPath.row]objectForKey:@"classname"];
      cell.markLabel.text=[[mustudentArr3 objectAtIndex:indexPath.row]objectForKey:@"typename"];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self detailView:[mustudentArr3 objectAtIndex:indexPath.row]];
}
-(void)detailView:(NSDictionary *)dict
{
    backView=[[UIView alloc]initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.origin.y, self.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
    backView.backgroundColor=[UIColor blackColor];
    backView.alpha=0.9;
    backView.userInteractionEnabled=YES;
    [self.window addSubview:backView];
    
    UIView *secondView=[[UIView alloc]initWithFrame:CGRectMake(0, 100, self.frame.size.width, self.frame.size.height-100)];
    secondView.backgroundColor=[UIColor whiteColor];
    [backView addSubview:secondView];
    
    UILabel *lable01=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)];
    lable01.text=@"宝宝";
    [secondView addSubview:lable01];
    
    UILabel *lable011=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable01.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable011.text=[dict objectForKey:@"studentname"];
    [secondView addSubview:lable011];
    
    UILabel *lable02=[[UILabel alloc]initWithFrame:CGRectMake(10, lable01.frame.origin.y+lable01.frame.size.height+10, 100, 20)];
    lable02.text=@"开始时间";
    [secondView addSubview:lable02];
    
    UILabel *lable022=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable02.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable022.text=[dict objectForKey:@"starttime"];
    [secondView addSubview:lable022];

    
    UILabel *lable03=[[UILabel alloc]initWithFrame:CGRectMake(10, lable02.frame.origin.y+lable02.frame.size.height+10, 100, 20)];
    lable03.text=@"结束时间";
    [secondView addSubview:lable03];
    
    UILabel *lable033=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable03.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable033.text=[dict objectForKey:@"endtime"];
    [secondView addSubview:lable033];

    
    UILabel *lable04=[[UILabel alloc]initWithFrame:CGRectMake(10, lable03.frame.origin.y+lable03.frame.size.height+10, 100, 20)];
    lable04.text=@"请假类型";
    [secondView addSubview:lable04];
    
    UILabel *lable044=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable04.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable044.text=[dict objectForKey:@"typename"];
    [secondView addSubview:lable044];
    
    UILabel *lable05=[[UILabel alloc]initWithFrame:CGRectMake(10, lable04.frame.origin.y+lable04.frame.size.height+10, 100, 20)];
    lable05.text=@"请假原因";
    [secondView addSubview:lable05];
    
    UILabel *lable055=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable05.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable055.text=[dict objectForKey:@"scontent"];
    [secondView addSubview:lable055];
    
    UILabel *lable06=[[UILabel alloc]initWithFrame:CGRectMake(10, lable05.frame.origin.y+lable05.frame.size.height+10, 100, 20)];
    lable06.text=@"家长";
    [secondView addSubview:lable06];
    
    UILabel *lable066=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable06.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable066.text=[dict objectForKey:@"parentname"];
    [secondView addSubview:lable066];
    
    UILabel *lable07=[[UILabel alloc]initWithFrame:CGRectMake(10, lable06.frame.origin.y+lable06.frame.size.height+10, 100, 20)];
    lable07.text=@"家长电话";
    [secondView addSubview:lable07];
    
    UILabel *lable077=[[UILabel alloc]initWithFrame:CGRectMake(lable01.frame.origin.x+lable01.frame.size.width, lable07.frame.origin.y, self.frame.size.width-lable01.frame.origin.x-lable01.frame.size.width-10, 20)];
    lable077.text=[dict objectForKey:@"parentmobile"];
    [secondView addSubview:lable077];
    
    UIButton *closeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    closeBtn.frame=CGRectMake(20, lable07.frame.origin.y+lable07.frame.size.height+20, self.frame.size.width-40, 50);
    [closeBtn setTitle:@"关闭" forState:UIControlStateNormal];
    [closeBtn setTintColor:[UIColor whiteColor]];
    [closeBtn setBackgroundColor:RGBACOLOR(0, 180, 255, 1)];
    [closeBtn addTarget:self action:@selector(closeTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    [secondView addSubview:closeBtn];
    
    
}
-(void)closeTouchAction:(UIButton *)sender
{
    [backView removeFromSuperview];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
